#include "SkyBox.h"
#include "ResourceManager.h"

SkyBox::SkyBox()
{

}


SkyBox::~SkyBox()
{

}

void SkyBox::Draw(float _cameraX, float _cameraY, float _cameraZ)
{
	m_pos = Vector3(_cameraX, _cameraY, _cameraZ);
	
	glPushMatrix();
	glEnable(GL_TEXTURE_2D);
	glColor4f(1, 1, 1, 1);
	glTranslatef(m_pos.X, m_pos.Y, m_pos.Z);
	float xx, yy, zz, aa;
	xx = m_size.X /2;
	yy = m_size.Y /2;
	zz = m_size.Z /2;
	aa = 0.5;
		
		ResourceManager::GetInst()->LoadTexture("Resource/texture/Sky Box/back.png");
		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-xx - aa,yy + aa,zz);//front
		glTexCoord2f(0.0f, 1.0f); glVertex3f(xx + aa,yy + aa,zz);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(xx + aa,-yy - aa,zz);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-xx - aa,-yy - aa,zz);
		glEnd();
		ResourceManager::GetInst()->LoadTexture("Resource/texture/Sky Box/front.png");
		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(xx + aa,yy + aa,-zz);//back
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-xx - aa,yy + aa,-zz);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-xx - aa,-yy - aa,-zz);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(xx + aa,-yy - aa,-zz);
		glEnd();
		ResourceManager::GetInst()->LoadTexture("Resource/texture/Sky Box/left.png");
		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-xx,yy + aa,-zz - aa);//l
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-xx,yy + aa,zz + aa);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-xx,-yy - aa,zz + aa);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-xx,-yy - aa,-zz - aa);
		glEnd();
		ResourceManager::GetInst()->LoadTexture("Resource/texture/Sky Box/right.png");
		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(xx,yy + aa,zz + aa);//r
		glTexCoord2f(0.0f, 1.0f); glVertex3f(xx,yy + aa,-zz - aa);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(xx,-yy - aa,-zz - aa);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(xx,-yy - aa,zz + aa);
		glEnd();
		ResourceManager::GetInst()->LoadTexture("Resource/texture/Sky Box/top.png");
		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(xx + aa,yy,zz + aa);//top
		glTexCoord2f(1.0f, 0.0f); glVertex3f(xx + aa,yy,-zz - aa);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-xx - aa,yy,-zz - aa);
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-xx - aa,yy,zz + aa);
		glEnd();
		ResourceManager::GetInst()->LoadTexture("Resource/texture/Sky Box/bottom.png");
		glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3f(xx + aa,-yy,-zz - aa);//bot
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-xx - aa,-yy,-zz - aa);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-xx - aa,-yy,zz + aa);
		glTexCoord2f(1.0f, 0.0f); glVertex3f(xx + aa,-yy,zz + aa);
		glEnd();

	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}
